package top.hymsk.ecommerce.pojo.DTO;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import top.hymsk.ecommerce.pojo.DO.OrderOverviewDO;
import top.hymsk.ecommerce.utils.DecimalUtils;
import top.hymsk.ecommerce.utils.TimeUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * @author 花于陌上开
 */
@Data
public class OrderDetailDTO {
    List<Product> productList;
    Integer status;
    Integer orderId;
    String createTime;
    Double actualPrice;

    public OrderDetailDTO(OrderOverviewDO orderDO) {
        this.createTime = TimeUtils.formatTime(orderDO.getCreateTime());
        this.orderId = orderDO.getOrderId();
        this.actualPrice =DecimalUtils.round(orderDO.getActualPrice()) ;
        this.status = orderDO.getStatus();
        List<Integer> numberList = Arrays.stream(orderDO.getNumberList().split(",")).map(Integer::parseInt).collect(Collectors.toList());
        List<Integer> statusList = Arrays.stream(orderDO.getStatusList().split(",")).map(Integer::parseInt).collect(Collectors.toList());
        List<Integer> productIdList = Arrays.stream(orderDO.getProductList().split(",")).map(Integer::parseInt).collect(Collectors.toList());
        List<String> titleList = Arrays.stream(orderDO.getTitleList().split(",\\|\\|,")).collect(Collectors.toList());
        List<String> filePathList = Arrays.stream(orderDO.getFilePathList().split(",")).collect(Collectors.toList());
        this.productList = IntStream.range(0, productIdList.size())
                .mapToObj(i -> new Product(productIdList.get(i), statusList.get(i), numberList.get(i),titleList.get(i),filePathList.get(i)))
                .collect(Collectors.toList());
    }
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Product{
        Integer productId;
        Integer status;
        Integer number;
        String title;
        String filePath;
    }

}
